package com.itheima.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author wuli
 * @create 2021-11-28 10:55
 */
public class ProxyTest {

    public static void main(String[] args) {

        final Target target = new Target();

        final Advice advice = new Advice();

        TargetInterface proxy = (TargetInterface)Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                advice.before();
                Object obj = method.invoke(target, args);
                advice.afterReturning();
                return obj;
            }
        });

        proxy.save();
    }
}
